#include "gtest/gtest.h"
#include <acapella/worker/thread_worker.hpp>

using namespace acapella::worker;

int ThreadWorkerTestFunction(int i, int a, int b)
{
    printf("%d %d %d\n",i,a,b);
    return i;
}

TEST(testThreadWorker, CompileTest)
{
    ThreadWorker<int(int, int , int)> tw(&ThreadWorkerTestFunction);

    tw.AsynCall(1, 2 ,3);
    tw.AsynCall(1, 2 ,4);
    tw.AsynCall(1, 2 ,5);
    tw.AsynCall(1, 2 ,6);
    tw.AsynCall(1, 2 ,7);
    tw.AsynCall(1, 2 ,8);

    tw.Exit();
    tw.Join();
}

TEST(testThreadWorker, CompeteTest)
{
    ThreadWorker<int(int, int , int)> tw1(&ThreadWorkerTestFunction);
    ThreadWorker<int(int, int , int)> tw2(&ThreadWorkerTestFunction);

    tw1.AsynCall(1, 2 ,3);
    tw2.AsynCall(1, 2 ,4);
    tw1.AsynCall(1, 2 ,5);
    tw2.AsynCall(1, 2 ,6);
    tw1.AsynCall(1, 2 ,7);
    tw2.AsynCall(1, 2 ,8);

    tw1.Exit();
    tw2.Exit();
    tw2.Join();
    tw1.Join();
}
